package cn.itcast.star.graph.core.service.impl;

import cn.itcast.star.graph.core.service.OllamaService;
import cn.itcast.star.graph.ollama.client.api.OllamaApi;
import cn.itcast.star.graph.ollama.client.pojo.OllamaChatRequest;
import cn.itcast.star.graph.ollama.client.pojo.OllamaChatRespone;
import cn.itcast.star.graph.ollama.client.pojo.OllamaMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import retrofit2.Call;
import retrofit2.Response;

import java.util.List;

@Service
public class OllamaServiceImpl implements OllamaService {

    @Autowired
    OllamaApi ollamaApi;

    @Override
    public String translate(String prompt) {
            OllamaMessage message = OllamaMessage.builder()
                    .role("user")
                    .content("用英文翻译以下内容:" + prompt)
                    .build();

            OllamaChatRequest body = OllamaChatRequest.builder()
                    .model("qwen2.5:0.5b")
                    .messages(List.of(message))
                    .build();

        try {
            Call<OllamaChatRespone> call = ollamaApi.chat(body);
            Response<OllamaChatRespone> response = call.execute();
            return response.body().getMessage().getContent();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return prompt;
    }
}
